// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import qs from 'qs'
import 'normalize.css'
import './styles/reset.css'
import axios from './http'
import store from './store'
import './assets/iconfont/iconfont.css'
import ElementUI from 'element-ui'
import { Message } from 'element-ui'
import '../node_modules/element-ui/lib/theme-chalk/index.css'
import '../node_modules/element-ui/lib/theme-chalk/display.css'
import '../node_modules/ztree/css/zTreeStyle/zTreeStyle.css'
import 'ztree'
import echarts from 'echarts'
import VideoPlayer from '../node_modules/vue-video-player'
import "video.js/dist/video-js.css";
import "vue-video-player/src/custom-theme.css";


//文件上传专用接口调用
var instance = axios.create({
  baseURL:'AIProjectApi',
  withCredentials: true,
  headers: {
    'Content-Type': 'multipart/form-data;boundary=' + new Date().getTime(),
    'Authorization':window.localStorage.getItem("token"),
  }
});

Vue.use(ElementUI);
Vue.use(VideoPlayer);
Vue.prototype.$echarts = echarts
Vue.prototype.$http = axios;
Vue.prototype.$instance = instance;
axios.defaults.baseURL = 'AIProjectApi'//axios请求默认地址
Vue.config.productionTip = false
//post请求处理数据用
Vue.prototype.qs = qs;

//页面刷新时，重新赋值有没有登录
if (window.localStorage.getItem('isLogin')) {
  store.commit('setIsLogin', window.localStorage.getItem('isLogin'));
}
// //登录首位
router.beforeEach((to, from, next) => {
  //登录界面清除localStorage
  if (to.path == '/' || to.path == '/login') {
    localStorage.removeItem('isLogin')
    localStorage.removeItem('userInfo')
    localStorage.removeItem('token')
  }
  if (to.matched.some(record => record.meta.requireAuth)) {
    // 判断该路由是否需要登录权限,true已经登录false没登录。
    if (store.getters.isLogin) { // 通过vuex 如果当前有登录
      next();
    } else {
      Message("登录无效,请重新登录");
      next({
        path: '/login',
        query: {
          redirect: to.fullPath
        }
      })
    }
  } else {
    next();
  }
});
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
